<template>
<div>

  <div class="search"><h3>全局搜索</h3>
   <h3 style="color: #888;font-weight: 400">--- Search ---</h3></div>

  <div class="indexContain">
    <div class="cardBox">
     <el-carousel trigger="click" height="400px" style="position: sticky;">
          <el-carousel-item v-for="(item, key) in crouselImg" :key="key">
            <img :src="item.img" class="boxImg" >
          </el-carousel-item>
        </el-carousel>
    </div>
  </div>

  <div class="division"><h3>热门企业</h3>
                        <h3 style="color: #888;font-weight: 400">--- Hot ---</h3></div>

  <div class="cardContain">
    <div class="wrapper-input">
      <el-input v-model="name" style="width: 400px"  placeholder="搜索心仪的公司">
        <el-button slot="append" icon="el-icon-search" @click="getCompany"></el-button>
      </el-input>
    </div>
    <div class="wrapper-card">
      <div class="card" v-for="(item, key) in companyList" :key="key" @click="getCompanyDetail(item.id)">
        <!--<img :src="item.avatar" class="image" @click="getCompanyDetail(item.id)">-->
        <div style="margin-top: 110px">
          <span > {{ item.name }} </span>
        </div>
    </div>
    </div>
    <el-pagination
      :page-size="page.size"
      :pager-count="11"
      layout="prev, pager, next"
      :total="page.total"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
  </div>
  <!--热门职位-->
  <div class="division">
    <h3>热门职位</h3>
    <h3 style="color: #888;font-weight: 400">--- JOBS ---</h3>
  </div>
  <div class="newsContain">
    <div class="temp">
    <div class="newsItem"  v-for = "(item, key) in jobList" :key = "key" @click="jobDetail(item.id)">
      <div class="picContain" ontouchstart="this.classList.toggle('hover');">
        <div class="flipper">
      <span class="itemPic">{{item.company.name}}</span>
      <span class="back">{{item.company.type}}</span>
        </div>
    </div>
    <div>
      <p>{{item.title}}</p>
      <p style="margin-top:25px">{{item.empltype}}</p>
      </div>
    </div>
    </div>
  </div>

  <div class="aboutus">
    <div id="aboutusInfo">
    <h2>关于我们</h2>
    <p>伯乐慧眼千里马，千寻招聘天下士！</p>
    <p>有些人可能一辈子都不知道自己的潜力在哪，</p>
    <p>与其浪费天赋，</p>
    <p>不如在千寻招聘找一份合适的工作，</p>
    <p>赶紧行动吧！</p>
    </div>
  </div>
  <div class="division"><h3>联系我们</h3>
    <h3 style="color: #888;font-weight: 400">--- CONTACT ---</h3></div>
  <div class="footer">
    <a href="https:baidu.com"><img src=""><span>我是一个保安，每天郁郁寡欢，上班只为下班</span></a>
  </div>
</div>
</template>

<style>
@import "../css/index.css";
@import "../assets/Animate/animate.min.css";
body {
  background: #ededed;
}

.myMenu {
  position: sticky;
  top: 0;
  z-index: 100;
}

.indexContain {
  width: 100%;
  height: 100%;
  border:1px solid #ededed;
  background: #fff;
}

.cardContain {
  width: 100%;
  height: 100%;
  background: #fff;
}
.wrapper-input {
  padding-top: 15px;
  margin-left: 750px;
}
.newsContain {
  padding-top: 1px;
  width: 100%;
  height: 100%;
  background: #fff;
}

.picContain {
  margin-right: 10px;
  perspective: 1000px;
}

.picContain:hover .flipper, .picContain.hover .flipper{
  transform: rotateY(180deg);
}

.picContain, .itemPic, .back{
  width: 80px;
  height: 80px;
}

.flipper {
  transition: 0.6s;
  transform-style:preserve-3d;
  position: relative;
}

.newsItem {
  display: flex;
  justify-content: flex-start;
  width: 1200px;
  margin: auto;
  height: 114px;
  text-align: left;
  color: #5a5a5a;
  font-weight: 500;
  padding-top: 15px;
  border-bottom: 1px solid #ededed;
}

.itemPic, .back {
  position: absolute;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  background: #cc0000;
  text-align: center;
  color: white;
  font-weight: 500;
  line-height: 80px;
  white-space: nowrap;
}

.itemPic {
  z-index: 2;
}

.back {
  transform: rotateY(180deg);
}

.footer {
  width: 100%;
  height: 100px;
  background: black;
  padding-top:20px
}

.footer a {
  color: white;
  text-decoration: none;
}

.aboutus  {
  width: 100%;
  height: 500px;
  background: url(../assets/index_bg.jpg) no-repeat;
  background-size: 100% 100%;
  filter: grayscale(70%);
  opacity: 0.7;
  color: white;
  font-weight: 600;
  padding-top: 60px;
}

.aboutus p{
  margin-top: 30px;
  font-size: 18px;
}

#aboutusInfo {
  margin-top: 80px;
  animation-delay: 1s
}

.cardBox {
  position: relative;
  width: 1200px;
  margin: 20px auto 30px auto;
  box-shadow: 0 10px 15px #888;
  border-radius: 6px;
}

.wrapper-card {
  width: 1200px;
  height:930px;
  margin: 0px auto auto auto;
}

.wrapper-card .card {
  color: #07111B;
  font-size: 16px;
  width: 336px;
  height: 243px;
  float: left;
  margin: 30px;
  border-radius: 6px;
  background: url(../assets/company.jpg);
}

.wrapper-card .card:hover {
  transform: translateY(-5px);
  transition: 3ms;
  box-shadow: 5px 5px 10px #888;
}

.wrapper-card .image {
  border-radius: 6px 6px 0 0;
  width: 100%;
  height: 100%;
  margin-bottom: 20px;
  border-radius: 6px;
}

.boxImg {
  width: 100%;
  height: 100%;
  border-radius: 6px;
}

.division {
  width: 100%;
  margin: 30px  auto;
  text-align: center;
  padding-left: 10px;
   color: #5a5a5a;
}

.footer img{
  width:25px;
  height: 25px;
  margin-right: 10px
}

.footer span {
  margin-right: 20px;
}

.recommand {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 36px 0;
  font-size: 18px;
}

.recommandList {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  color: #5a5a5a;
  font-weight: 500;
}

.recommandInfo {
  margin-left: 16px;
}

.recommandInfo p {
  margin-bottom: 6px;
}

.el-progress__text {
  font-size: 16px !important;
  text-align: center !important;
}

.el-carousel-item {
  display: flex;
  justify-content: space-around;
}

.el-carousel {
  width: 1200px;
  margin: 0 auto;
}

.recommandJob {
  border: 1px solid #ebebeb;
  text-align: left;
  color: #fff;
  line-height: 30px;
  background: linear-gradient(#948E99, #2E1437);
  border-radius: 4px;
  width: 150px;
  height: 180px;
  padding: 20px 10px 10px;
  font-weight: bold;
}

.mytable {
  width: 100%;
  height: 700px;
}

.progress2 {
  width: 182px;
  border: 0;
}

</style>
<script>
import fetch from '../api/fetch'
export default {
  data () {
    return {
      crouselImg: [
        {img: 'https://sxsimg.xiaoyuanzhao.com/adservice/image/20200605134308U5kXBpEmy5Lm6Xl8y4.png'},
        {img: 'https://sxsimg.xiaoyuanzhao.com/adservice/image/202006290902185XVlqblNhkh2SDozSX.png'},
        {img: 'https://sxsimg.xiaoyuanzhao.com/adservice/image/20200629112838VOAcUDchDe3ZCJUmMR.png'},
        {img: 'https://sxsimg.xiaoyuanzhao.com/adservice/image/20191010092700tZ5m7EmN2Rx79PdjIL.png'}

      ],
      page: {
        count: 1,
        size: 9,
        total: 2000
      },
      name: '',
      activeIndex2: '1',
      currentDate: '完美',
      company: '',
      companyList: [],
      jobList: [],
      recommandList: [],
      isHr: localStorage.getItem('role') === '1',
      isLogin: localStorage.getItem('token') ? true : false,
      isShow: false,
      getResumeList: {
        name: '',
        sex: '',
        age: '',
        skills: [{
          id: 1,
          name: '',
          level: '',
          resumeId: 1
        }],
        school: '',
        address: '',
        endTime: 2019,
        phone: '',
        email: '',
        introduce: '',
        experience: '',
        awards: '',
        avatar: ''
      },
    }
  },

  mounted () {
    window.addEventListener('scroll', this.handler)
    this.getCompany()
    this.getJob()
    this.getRecommand()
  },
  methods: {
    handleCurrentChange(val) {
      console.log(`每页 ${val} 条`)
      this.page.count = val
      this.getCompany()
    },
    handler () {
      let info = document.getElementById('aboutusInfo') || null
      let card = document.getElementsByClassName('temp')[0] || null
      if (info === null || card === null) {
        return;
      } else if (document.documentElement.scrollTop > 1000) {
        card.classList.add('animated')
        card.classList.add('bounceInLeft')
        info.classList.add('animated')
        info.classList.add('bounceInLeft')
      } else {
        info.classList.remove('animated')
        info.classList.remove('bounceInLeft')
        card.classList.remove('animated')
        card.classList.remove('bounceInLeft')
      }
    },

    jobDetail (id) {
      localStorage.setItem('jobId', id)
      this.$router.push({name: 'jobInfo'})
    },

    getJob () {
      fetch.findJob().then(res => {
        if (res.status === 200) {
          this.jobList = res.data
          console.log('test', this.jobList)
        }
      }).catch(e => {
        console.log(e)
      })
    },

    getCompany () {
      fetch.getCompany(this.name, this.page.count).then(res => {
        if (res.status === 200) {
          this.companyList = res.data.records;
          this.page.total = res.data.total;
        }
      })
    },

    getCompanyDetail (id) {
      localStorage.setItem('companyId', id)
      this.$router.push({name: 'companyDetail'})
    },
    // 获取推荐列表
    getRecommand () {
      if (this.isLogin) {
        if (this.isHr) {
        fetch.recommendCandidate().then(res => {
          if (res.status === 200) {
            this.recommandList = res.data.data
          }
        })
      } else {
        fetch.recommendJob().then(res => {
        if (res.status === 200) {
          this.recommandList = res.data.data
        }
      })
      }
    }
  },
  // 查看推荐候选人
  getTableList(id) {
      this.isShow = true
        fetch
          .getResume(id)
          .then(res => {
            if (res.status === 200) {
              if (res.data.success === true) {
                if (res.data.data !== null) {
                  this.getResumeList = res.data.data
                }
              }
            }
          })
          .catch(e => {
            console.log(e)
          })
      }
},

}
</script>
